#include<iostream>
#include<string>
#include<vector>
#include<cmath>
using namespace std;


template<size_t N>
class bitset
{
public:
	typedef bitset<N> self;

	bitset()
	{
		_bitmap.resize(ceil(N / 32.0),0);
	}

	self& set()
	{
		for (int i = 0; i < _bitmap.size(); i++)
		{
			_bitmap[i] = 0XFFFFFFFF;
		}
		return *this;
	}

	self& set(size_t pos, bool check = true)
	{
		int i = pos / 32;
		int j = pos % 32;
		
		if (check)
		{
			_bitmap[i] |= (1 << j);
		}
		else
		{
			reset(pos);
		}

		return *this;
	}

	bool test(size_t pos) const
	{
		int i = pos / 32;
		int j = pos % 32;

		if (i >= _bitmap.size())
		{
			throw string("Access out of bounds error");
			return false;
		}
		return ((_bitmap[i] >> j) & 1);
	}

	self& reset()
	{
		for (int i = 0; i < _bitmap.size(); i++)
		{
			_bitmap[i] = 0;
		}
		return *this;
	}

	self& reset(size_t pos)
	{
		int i = pos / 32;
		int j = pos % 32;

		if (test(pos))
		{
			_bitmap[i] ^= (1 << j);
		}

		return *this;
	}

	size_t count() const
	{
		size_t ans = 0;
		for (size_t i = 0; i <= N; i++)
		{
			if (test(i))
			{
				ans++;
			}
		}
		return ans;
	}

	self& flip()
	{
		for (int i = 0; i < _bitmap.size(); i++)
		{
			_bitmap[i] ^= 0XFFFFFFFF;
		}
		return *this;
	}

	self& flip(size_t pos)
	{
		int i = pos / 32;
		int j = pos % 32;

		_bitmap[i] ^= (1 << j);
		return *this;
	}

private:
	vector<int> _bitmap;
};